package ch15;

import java.util.LinkedList;
import java.util.List;

public class Company {
    private String companyName;
    private String address;
    private String phone;
    private String range;
    List liststaff=new LinkedList();

    public Company() {
    }

    public Company(String companyName, String address, String phone, String range) {
        this.companyName = companyName;
        this.address = address;
        this.phone = phone;
        this.range = range;
    }

    public String getCompanyName() {
        return companyName;
    }

    public void setCompanyName(String companyName) {
        this.companyName = companyName;
    }

    public String getAddress() {
        return address;
    }

    public void setAddress(String address) {
        this.address = address;
    }

    public String getPhone() {
        return phone;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public String getRange() {
        return range;
    }

    public void setRange(String range) {
        this.range = range;
    }

    //添加员工
    public boolean setListstaff(Staff staff) {
        for(int i=0;i<liststaff.size();i++) {
            Staff staff1=(Staff)liststaff.get(i);
            if (staff.getNo().equals(staff1.getNo())){
                return false;
            }
       }
        liststaff.add(staff);
        return true;
    }

    //显示员工信息
    public void showStaff(){
        for(Object o:liststaff){
            Staff s=(Staff)o;
            System.out.println("姓名："+s.getName()+",年龄："+s.getAge()+",性别："+s.getGender()+
                    "职位:"+s.getPost()+",薪资："+s.getSalary()+",工号："+s.getNo());
        }
    }

    //显示公司信息(String companyName, String address, String phone, String range)
    public void showCompany(){
        System.out.println("公司信息如下：");
        System.out.println("公司名称:"+companyName+",注册地址："+address+
                ",公司电话："+",公司经营范围："+range+",公司现有"+liststaff.size()+"人");
    }

    //显示工资最高的员工信息
    public void maxSalary(){//有问题：
        if(liststaff.size()==0){
            System.out.println("还没有员工");
        }else {
            double[] max = new double[liststaff.size()];
            double realMax = 0;
            int index = 0;
            //将员工薪资放进数组中
            for (int i = 0; i < liststaff.size(); i++) {
                Staff staff = (Staff) liststaff.get(i);
                max[i] = staff.getSalary();

            }

            realMax=max[0];
            //获取员工薪资的最大值和对应的索引
            for (int j = 0; j < max.length; j++) {
                if (realMax < max[j]) {
                    realMax=max[j];
                    index = j;
                }

            }
            Staff maxStaf = (Staff) liststaff.get(index);
            maxStaf.show();
        }
    }

    //开除员工
    public boolean delete(String no){
        int in=0;
        for(int i=0;i<liststaff.size();i++) {
            Staff deleteStaff = (Staff) liststaff.get(i);
            if (no.equals(deleteStaff.getNo())){
                in=i;
                liststaff.remove(in);
                return true;
            }
        }
        return false;
    }

}
